//
//  BaseNavigation.m
//  安好
//
//  Created by 冯凯 on 14-10-27.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "BaseNavigation.h"

@interface BaseNavigation ()

@end

@implementation BaseNavigation
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
//        self.navigationBarHidden = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    /**
     *  设置navigation的背景颜色和字体的颜色
     */
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [[UINavigationBar appearance] setBarTintColor:[ClassMethodsViewController colorWithHexString:NACIGATIONBAR_BACKGROUNDCOLOR_16]];
    
    __block UIView * navBottomLine = nil;
    [self.navigationBar.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]){
            UIView* v = obj;
            if (v.subviews.count)
            {
                navBottomLine = [v.subviews objectAtIndex:0];
            }
            *stop=YES;
        }
    }];
    navBottomLine.hidden = YES;
    
    self.navigationBar.translucent = NO;
    
    NSShadow *shadow = [[NSShadow alloc] init];
    shadow.shadowOffset = CGSizeMake(0, 1);
    [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor whiteColor], NSForegroundColorAttributeName,
                                                           nil, NSShadowAttributeName,
                                                           [UIFont systemFontOfSize:18], NSFontAttributeName, nil]];
    /**
     *  是否开启手势返回
     *
     *  @param respondsToSelector:@selectorinteractivePopGestureRecognizer 
     *  是否开启手势返回的方法
     *
     *  @return 无
     */
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tabbarHiden) name:@"tabbarHiden" object:nil];//解决分享取消后tabbar不消失

}
-(void)tabbarHiden{
    UIViewController *parentViewController = [self.viewControllers lastObject];

    parentViewController.tabBarController.tabBar.hidden = YES;
}

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    UIViewController *parentViewController = [self.viewControllers lastObject];
    UIViewController *rootViewController = [self.viewControllers firstObject];
    
    parentViewController.hidesBottomBarWhenPushed = YES;
    [super pushViewController:viewController animated:animated];
    rootViewController.hidesBottomBarWhenPushed = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
